package personnel.department.pages.widgets;

import java.lang.reflect.Field;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

public class CheckedWidget extends AbstractWidget<Boolean> {

	private String title;
	private Composite parent;
	private Button check;

	public CheckedWidget(Composite parent,  String title, Field field) {
		super(field);
		this.parent = parent;
		this.title = title;
		create();
	}

	@Override
	protected void create() {
		Label label = new Label(parent, SWT.NONE);
		label.setText(title);
		check = new Button(parent, SWT.CHECK);
		check.addListener(SWT.Selection, event -> modify());
		super.create();
	}

	@Override
	public void setValue(Boolean value) {
		check.setSelection(value);
		modify();
	}

	@Override
	public Boolean getValue() {
		return check.getSelection();
	}

	@Override
	protected Control getWidget() {
		return check;
	}

}
